﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using QAS.NekoramaMVC4.Models;

namespace QAS.NekoramaMVC4.Controllers
{
    public class QuestionController : Controller
    {
        //
        // GET: /Question/

        public ActionResult Index()
        {
            return View();
        }

        //
        // GET: /Question/Details/5

        public ActionResult Details(int id)
        {
            var model = new QuestionDetailModel();
            var db = new Entities();
            var res = from r in db.Questions.AsEnumerable()
                             where (r.QuestionID == 1)
                             select r;
            var ans = (from a in db.Answers.AsEnumerable()
                where (a.QuestionID == 1)
                select a);
            model.Answers = ans.ToList();
            var cmm = (from c in db.Comments.AsEnumerable()
                       where (c.QuestionID == 1)
                       select c);
            model.Comments = cmm.ToList();
            model.Question = res.ToList()[0];
            return View(model);
        }

        //
        // GET: /Question/Create

        public ActionResult Create()
        {
            return View();
        }

        //
        // POST: /Question/Create

        [HttpPost]
        public ActionResult Create(FormCollection collection)
        {
            try
            {
                // TODO: Add insert logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /Question/Edit/5

        public ActionResult Edit(int id)
        {
            return View();
        }

        //
        // POST: /Question/Edit/5

        [HttpPost]
        public ActionResult Edit(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add update logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /Question/Delete/5

        public ActionResult Delete(int id)
        {
            return View();
        }

        //
        // POST: /Question/Delete/5

        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add delete logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
    }
}
